﻿using System.Collections.Generic;
using DotNetNuke.ComponentModel;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Permissions;

namespace BrandonHaynes.Providers.AmazonS3.Permissions
	{
	/// <summary>
	/// This class is intended as an example DotNetNuke permission provider that gives 
	/// page-admin and page-export authorization to any user named "Brandon".
	/// 
	/// It is NOT RECOMMENDED FOR PRODUCTION USE!
	/// </summary>
	public class MagicUserNamePermissionProvider 
		: PermissionProvider
		{
		#region Provider Settings
		public Dictionary<string, string> Settings
			{ get { return ComponentFactory.GetComponentSettings<MagicUserNamePermissionProvider>() as Dictionary<string, string>; } }
		#endregion

		/// <summary>
		/// For any user named "Brandon", grant admin authorization.  Otherwise, rely on base 
		/// functionality.
		/// </summary>
		public override bool CanAdminPage(TabInfo objTab)
			{
			if(UserController
				.GetCurrentUserInfo()
				.Username == "Brandon")
				return true;
			else
				return base.CanAdminPage(objTab);
			}

		/// <summary>
		/// For any user named "Brandon", grant export authorization.  Otherwise, rely on base
		/// functionality.
		/// </summary>
		/// <param name="objTab"></param>
		/// <returns></returns>
		public override bool CanExportPage(TabInfo objTab)
			{
			if (UserController
				.GetCurrentUserInfo()
				.Username == "Brandon")
				return true;
			else
				return base.CanExportPage(objTab);
			}
		}
	}
